package com.htj.admin.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.htj.admin.dao.FoodTypeDao;
import com.htj.admin.dao.OrderDao;
import com.htj.admin.dao.OrderDetailDao;
import com.htj.admin.domain.Food;
import com.htj.admin.domain.FoodType;
import com.htj.admin.domain.Order;
import com.htj.admin.domain.OrderDetail;
import com.htj.admin.service.FoodTypeServiceInf;
import com.htj.admin.service.OrderServiceInf;
import com.htj.util.DateTimeUtil;
import com.htj.vo.PageListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class OrderServiceImpl implements OrderServiceInf {
    @Autowired
    OrderDao orderDao;
    @Autowired
    OrderDetailDao orderDetailDao;

    @Override
    public boolean add(Order order) {
        boolean bool = false;
        String time = DateTimeUtil.getSysTime();
        order.setCreateTime(time);
        int flag = orderDao.add(order);
        if(flag == 1){
            bool = true;
        }
        return bool;
    }

    @Override
    public PageListVo<Order> pageList(Map<String, String> map) {
        PageListVo<Order> pageListVo = new PageListVo<>();
        String currentPage = map.get("currentPage");
        String pageSize = map.get("pageSize");
        PageHelper.startPage(Integer.valueOf(currentPage),Integer.valueOf(pageSize));
        List<Order> list = orderDao.pageList(map);
        PageInfo<Order> pageInfo = new PageInfo<>(list);
        List<Order> pageInfoList = pageInfo.getList();
        int total = (int) pageInfo.getTotal();
        pageListVo.setList(pageInfoList);
        pageListVo.setTotal(total);
        return pageListVo;
    }


    @Override
    public boolean delete(Integer id) {
        boolean bool = false;
        int flag = orderDao.delete(id);
        if(flag == 1){
            bool = true;
        }
        return bool;
    }

    @Override
    public boolean changeStatus(Map<String,String> map) {
        boolean bool = false;
        int flag = orderDao.changeStatus(map);
        if(flag == 1){
            bool = true;
        }
        return bool;
    }

    @Override
    public List<OrderDetail> detail(String id) {
        List<OrderDetail> list = orderDetailDao.detail(id);
        return list;
    }

    @Override
    public PageListVo<Order> searchStatus(HashMap<String, String> map) {
        PageListVo<Order> pageListVo = new PageListVo<>();
        String currentPage = map.get("currentPage");
        String pageSize = map.get("pageSize");
        PageHelper.startPage(Integer.valueOf(currentPage),Integer.valueOf(pageSize));
        List<Order> list = orderDao.searchStatus(map);
        PageInfo<Order> pageInfo = new PageInfo<>(list);
        List<Order> pageInfoList = pageInfo.getList();
        int total = (int) pageInfo.getTotal();
        pageListVo.setList(pageInfoList);
        pageListVo.setTotal(total);
        return pageListVo;
    }


}
